class Video {
  final int id;
  final String title;
  final String videoUrl;
  final String thumbnailUrl;
  final String description;
  final int userId;
  final DateTime uploadTime;
  final int likes;
  final int comments;
  final int views;

  Video({
    required this.id,
    required this.title,
    required this.videoUrl,
    required this.thumbnailUrl,
    required this.description,
    required this.userId,
    required this.uploadTime,
    required this.likes,
    required this.comments,
    required this.views,
  });

  // 从JSONPlaceholder的/photos数据转换成Video对象
  factory Video.fromJson(Map<String, dynamic> json) {
    return Video(
      id: json['id'],
      title: json['title'] ?? '可爱的宠物视频',
      videoUrl: json['url'] ?? 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
      thumbnailUrl: json['thumbnailUrl'] ?? 'https://via.placeholder.com/150',
      description: '这是一个关于${json['title'] ?? '宠物'}的精彩视频，快来观看吧！',
      userId: json['albumId'] ?? 1,
      uploadTime: DateTime.now().subtract(Duration(days: (json['id'] ?? 1) % 30)),
      likes: (json['id'] ?? 1) * 10 % 1000,
      comments: (json['id'] ?? 1) * 3 % 200,
      views: (json['id'] ?? 1) * 100 % 10000,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'videoUrl': videoUrl,
      'thumbnailUrl': thumbnailUrl,
      'description': description,
      'userId': userId,
      'uploadTime': uploadTime.toIso8601String(),
      'likes': likes,
      'comments': comments,
      'views': views,
    };
  }
} 